//
//  ViewController.swift
//  foundationDemo
//
//  Created by Zhang Zhang on 16/6/20.
//  Copyright © 2016年 HNA. All rights reserved.
//

import UIKit
import WebKit
class ViewController:
        UIViewController,
        UITextFieldDelegate,
        UIWebViewDelegate,
        WKNavigationDelegate,
        UIAlertViewDelegate,
        UIActionSheetDelegate{
    
    
    @IBOutlet weak var textField: UITextField!
    @IBOutlet weak var ajaxhtml: UIButton!
    @IBOutlet weak var webview: UIWebView!
    @IBOutlet weak var alertView: UIButton!
    @IBOutlet weak var actionSheet: UIButton!
    @IBOutlet weak var nextPage: UIBarButtonItem!
    var webview1:WKWebView!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.textField.delegate = self
        
        self.webview1 = WKWebView(frame: CGRectMake(20, 420,
            280, 152))
        self.view.addSubview(self.webview1)
        self.alertView.hidden=true
        self.actionSheet.hidden=true
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    //异步加载webview
    @IBAction func loadHtml(sender: AnyObject) {
        self.alertView.hidden=false
        self.actionSheet.hidden=false
        let url = NSURL(string: "http://www.sina.com")
        let request = NSURLRequest(URL: url!)
        self.webview.loadRequest(request)
        self.webview.delegate = self
        
        let url1 = NSURL(string: "http://www.qq.com")
        let request1 = NSURLRequest(URL: url1!)
        self.webview1.loadRequest(request1)
        self.webview1.navigationDelegate = self
    }
    func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
        print(error)
    }
    //警告窗
    @IBAction func alertView(sender: AnyObject) {
        var alertView:UIAlertView = UIAlertView(title: "Warning", message: "有得屌你屌唔屌", delegate: self, cancelButtonTitle: "唔屌", otherButtonTitles: "屌")
        alertView.show()
    }
    @IBAction func showSheet(sender: AnyObject) {
        var actionSheet:UIActionSheet=UIActionSheet(title: nil, delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: "aaa",otherButtonTitles: "bbb")
        actionSheet.showInView(self.view)
    }
    
    
    
    //textField
    func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
        print("call textFieldShouldBeginEditing:")
        return true
    }
    func textFieldDidBeginEditing(textField: UITextField) {
        print("call textFieldBeginEditing:")
    }
    func textFieldShouldEndEditing(textField: UITextField) -> Bool {
        print("call textFieldShouldEndEditing:")
        return true

    }
    func textFieldDidEndEditing(textField: UITextField) {
        print("call textFieldEndEditing:")
    }
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        print("call textFieldShouldReturn:")
        textField.resignFirstResponder()
        print(textField.text)
        return true

    }

}

